﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YasharEl.Infrastructure.EntityModel;
using NHibernate.Linq;

namespace YasharEl.Infrastructure.PersistenceModel.NHibernate
{
    /// <summary>
    /// Helper class to convert NHibernate ISession to various data providers.
    /// </summary>
    public class NHibernateUnitOfWorkConvertor : IUnitOfWorkConvertor
    {
        /// <summary>
        /// Gets <see cref="INHibernateQueryable"/> from <see cref="ISession"/> wrapped
        /// in the given <see cref="NHibernateUnitOfWork"/> instance.
        /// </summary>
        public IQueryable<TEntity> ToQueryable<TEntity, TIdentity>(IUnitOfWork unitOfWork) where TEntity : class, IGenericEntity<TIdentity>
        {
            return (unitOfWork as NHibernateUnitOfWork).Session.Query<TEntity>();
        }
    }
}
